package com.zhuoshi.action;

import java.util.Date;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.zhuoshi.bean.Wd_reception_recordModel;
import com.zhuoshi.bean.Wd_userModel;
import com.zhuoshi.service.Wd_reception_recordModelService;

@Controller
@RequestMapping("/reception")
public class Wd_reception_recordAction {
	//查询全部
	@Autowired
	private Wd_reception_recordModelService receptionService;
	@RequestMapping("select_reception.do")
	public String selectAllReception(Wd_reception_recordModel bean,Model model){
		if (bean.getCustomerName() != null && "".equals(bean.getCustomerName().trim())) {
			bean.setCustomerName(null);
		}
		if (bean.getReceptionContent() != null && "".equals(bean.getReceptionContent().trim())) {
			bean.setReceptionContent(null);
		}
		List<Wd_reception_recordModel> list = receptionService.selectAllReception(bean);
		model.addAttribute("relist", list);
		return "Wd_reception_select";
	}
	//添加
	@RequestMapping("add_reception.do")
	public String insertReception(Wd_reception_recordModel record){
		record.setReceptionTime(new Date());
		//获取当前登录人
//		RequestAttributes ra = RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = ((ServletRequestAttributes)ra).getRequest();
//        Wd_userModel userbean = (Wd_userModel) request.getSession(true).getAttribute("user");
//		System.out.println(userbean.getName()+"name=================");
//		record.setUserName(userbean.getName());
		receptionService.insertSelective(record);
		return "redirect:select_reception.do";
	}
	//删除
	@RequestMapping("delete_reception.do")
	public String deleteReception(String receptionRecordId){
		receptionService.deleteByPrimaryKey(receptionRecordId);
		return "redirect:select_reception.do";
	}
	//修改获取值
	@RequestMapping("toupdate_reception.do")
	public String toupdateReception(Wd_reception_recordModel receptionBean,Model model){
		Wd_reception_recordModel receBean = receptionService.selectByPrimaryKey(receptionBean.getReceptionRecordId());
		model.addAttribute("reception", receBean);
		return "Wd_reception_update";
	}
	//修改
	@RequestMapping("update_reception.do")
	public String updateReception(Wd_reception_recordModel receptionBean){
 		receptionBean.setReceptionTime(new Date());
		receptionService.updateByPrimaryKeySelective(receptionBean);
		return "redirect:select_reception.do";
	}
	
}
